package db

import (
	"gitee.com/nanakura/h-scraper/internal/global"
	"gitee.com/nanakura/h-scraper/internal/model/entity"
	"gorm.io/driver/sqlite" // Sqlite driver based on GGO

	// "github.com/glebarez/sqlite" // Pure go SQLite driver, checkout https://github.com/glebarez/sqlite for details
	"gorm.io/gorm"
)

func InitDB() {
	// github.com/mattn/go-sqlite3
	db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	global.DB = db
	err = global.DB.AutoMigrate(&entity.SourceEntity{})
	if err != nil {
		panic(err)
	}
}
